package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.happy.cat.common.utils.SecurityUtils;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.*;
import com.happy.cat.project.system.domain.vo.UserManitoVo;
import com.happy.cat.project.system.service.*;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 大神申请审核Controller
 *
 * @author verne
 * @date 2020-08-13
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userManitoApply" )
@Api("大神申请审核 API")
public class UserManitoApplyController extends BaseController {

    private final IUserManitoApplyService iUserManitoApplyService;


    /**
     * 查询大神申请审核列表
     */
    @ApiOperation(value = "查询大神申请审核列表",notes = "查询大神申请审核列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserManitoApply userManitoApply)
    {
        startPage();
        LambdaQueryWrapper<UserManitoApply> lqw = new LambdaQueryWrapper<UserManitoApply>();
        if (userManitoApply.getAccountId() != null){
            lqw.eq(UserManitoApply::getAccountId ,userManitoApply.getAccountId());
        }
        if (userManitoApply.getGodId() != null){
            lqw.eq(UserManitoApply::getGodId ,userManitoApply.getGodId());
        }
        if (StringUtils.isNotBlank(userManitoApply.getGodLevel())){
            lqw.eq(UserManitoApply::getGodLevel ,userManitoApply.getGodLevel());
        }
        if (userManitoApply.getTeamCategoryItemId() != null){
            lqw.eq(UserManitoApply::getTeamCategoryItemId ,userManitoApply.getTeamCategoryItemId());
        }
        if (userManitoApply.getRegionId() != null){
            lqw.eq(UserManitoApply::getRegionId ,userManitoApply.getRegionId());
        }
        if (userManitoApply.getHighestStrengthId() != null){
            lqw.eq(UserManitoApply::getHighestStrengthId ,userManitoApply.getHighestStrengthId());
        }
        if (StringUtils.isNotBlank(userManitoApply.getSkilledPosition())){
            lqw.eq(UserManitoApply::getSkilledPosition ,userManitoApply.getSkilledPosition());
        }
        if (StringUtils.isNotBlank(userManitoApply.getSkilledRole())){
            lqw.eq(UserManitoApply::getSkilledRole ,userManitoApply.getSkilledRole());
        }
        if (StringUtils.isNotBlank(userManitoApply.getHighestStrengthScreenshot())){
            lqw.eq(UserManitoApply::getHighestStrengthScreenshot ,userManitoApply.getHighestStrengthScreenshot());
        }
        if (userManitoApply.getStatus() != null){
            lqw.eq(UserManitoApply::getStatus ,userManitoApply.getStatus());
        }
        if (StringUtils.isNotBlank(userManitoApply.getGatecorys())){
            lqw.eq(UserManitoApply::getGatecorys ,userManitoApply.getGatecorys());
        }
        List<UserManitoApply> list = iUserManitoApplyService.list(lqw);
        if(list.size()<=0){
            return getDataTable(list);
        }
        return getDataTable(iUserManitoApplyService.listVoItems(list));
    }

    /**
     * 查询大神申请审核列表
     */
    @GetMapping("/list/{accountId}")
    public AjaxResult listByAccount(@PathVariable("accountId" ) Long accountId)  {
        LambdaQueryWrapper<UserManitoApply> lqw = Wrappers.lambdaQuery(UserManitoApply.class)
                .eq(accountId != null, UserManitoApply::getAccountId ,accountId)
                .eq(UserManitoApply::getStatus,1)
                .orderByDesc(UserManitoApply::getCreateTime);
        List<UserManitoApply> list = iUserManitoApplyService.list(lqw);
        if(list.size()<=0){
            return AjaxResult.success(list);
        }
        return AjaxResult.success(iUserManitoApplyService.listVoItems(list));
    }


    /**
     * 导出大神申请审核列表
     */
    @ApiOperation(value = "导出大神申请审核列表",notes = "导出大神申请审核列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoApply:export')" )
    @Log(title = "大神申请审核" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserManitoApply userManitoApply) {
        LambdaQueryWrapper<UserManitoApply> lqw = new LambdaQueryWrapper<UserManitoApply>(userManitoApply);
        List<UserManitoApply> list = iUserManitoApplyService.list(lqw);
        ExcelUtil<UserManitoApply> util = new ExcelUtil<UserManitoApply>(UserManitoApply. class);
        return util.exportExcel(list, "userManitoApply" );
    }

    /**
     * 获取大神申请审核详细信息
     */
    @ApiOperation(value = "获取大神申请审核详细信息",notes = "获取大神申请审核详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoApply:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserManitoApplyService.getById(id));
    }

    /**
     * 新增大神申请审核
     */
    @ApiOperation(value = "新增大神申请审核",notes = "新增大神申请审核",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoApply:add')" )
    @Log(title = "大神申请审核" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserManitoApply userManitoApply) {
        return toAjax(iUserManitoApplyService.save(userManitoApply) ? 1 : 0);
    }

    /**
     * 修改大神申请审核
     */
    @ApiOperation(value = "修改大神申请审核",notes = "修改大神申请审核",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoApply:edit')" )
    @Log(title = "大神申请审核" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserManitoApply userManitoApply) {
        userManitoApply.setApplyTime(new Date());
        userManitoApply.setApplyBy(SecurityUtils.getUsername());
        return toAjax(iUserManitoApplyService.updateById(userManitoApply) ? 1 : 0);
    }

    /**
     * 删除大神申请审核
     */
    @ApiOperation(value = "删除大神申请审核",notes = "删除大神申请审核",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userManitoApply:remove')" )
    @Log(title = "大神申请审核" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserManitoApplyService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
